#-*-coding:utf-8-*-
import hou
class Viewports(object):
    def __init__(self):
        super(Viewports,self).__init__()

    def setOrientation(self,up):
        '''
        :param up: 0 / 'Y'  ,1 /'Z'
        :return:
        '''
        if up==0 or up=='Z':
            hou.setPreference('viewport.orientation.val','Y Up')
            # print('Y Up')

        elif up==1 or up=='Y':
            hou.setPreference('viewport.orientation.val', 'Z Up')
            # print('Z Up')

    def setOrientation(self):
        return hou.getPreference('viewport.orientation.val')
        # print('setOrientation')


    def setDefaultHomingMethod(self,methodNum):
        '''
        :param method: 0 - Oblique,1 - Custom,2 - X-Axis,3 - Y-Axis,4 - Z-Axis,
        5 - Front,6 - Right,7 - Top,8 - Back,9 - Left,10 - Bottom
        :return:
        '''
        hou.setPreference('viewport.defaulthoming.val', str(methodNum))
        # print('setDefaultHomingMethod')

    def getDefaultHomingMethod(self):
        return hou.getPreference('viewport.defaulthoming.val')
        # print('getDefaultHomingMethod')


    def setWireToggleMode(self,ModeNum):
        '''

        :param ModeNum: 0 - Wireframe Bounding Box,1 - Wireframe,2 - Wireframe Ghost,
        3 - Hidden Line Invisible,4 - Hidden Line Ghost
        :return:
        '''
        #hou.setPreference('viewport.wiretoggle.val','1')

        if ModeNum==0:
            hou.setPreference('viewport.wiretoggle.val', 'Wireframe Bounding Box')
            # print('Wireframe Bounding Box')
        elif ModeNum==1:
            hou.setPreference('viewport.wiretoggle.val', 'Wireframe')
            # print('Wireframe')

        elif ModeNum==2:
            hou.setPreference('viewport.wiretoggle.val', 'Wireframe Ghost')
            # print('Wireframe Ghost')

        elif ModeNum==3:
            hou.setPreference('viewport.wiretoggle.val', 'Hidden Line Invisible')
            # print('Hidden Line Invisible')
        elif ModeNum==4:
            hou.setPreference('viewport.wiretoggle.val', 'Hidden Line Ghost')
            # print('Hidden Line Ghost')

    def getWireToggleMode(self):
        return hou.getPreference('viewport.wiretoggle.val')
        # print('getWireToggleMode')



    def setTumblingMethod(self,methodNum):
        '''

        :param methodNum: 0 - Standard Houdini Tumbling, 1 - Classic Houdini Tumbling,
        2 - 80`s Style Euler Tumbling,3 - 90`s Style Euler Tumbling
        :return:
        '''
        hou.setPreference('viewport.oldtumble.val', str(methodNum))
        # print('setTumblingMethod')


    def getTumblingMethod(self):
        return hou.getPreference('viewport.oldtumble.val')
        # print('getTumblingMethod')



    def setPanningMethod(self,methodNum):
        '''

        :param methodNum: 0 - Move Pivot When Panning,
        1 - Maintain Viewport Pivot when Panning
        :return:
        '''
        hou.setPreference('viewport.scrollstyle.val', str(methodNum))
        # print('setPanningMethod')


    def getPanningMethod(self):
        return hou.getPreference('viewport.scrollstyle.val')
        # print('getPanningMethod')


    def setUseAltKeyForViewControls(self,bool):
        if bool==True:
            hou.setPreference('viewport.altkeyviewcontrols.val', '1')
            # print('True')

        else:
            hou.setPreference('viewport.altkeyviewcontrols.val', '0')
            # print('False')

    def getUseAltKeyForViewControls(self):
        return hou.getPreference('viewport.altkeyviewcontrols.val')
        # print('getUseAltKeyForViewControls')


    def setAutomaticallySetViewPivotOnSelection(self,bool):

        if bool == True:
            hou.setPreference('viewport.autosetviewpivotonselection.val', '1')
            # print('1')
        else:
            hou.setPreference('viewport.autosetviewpivotonselection.val', '0')
            # print('0')

    def getAutomaticallySetViewPivotOnSelection(self):
        return hou.getPreference('viewport.autosetviewpivotonselection.val')
        # print('getAutomaticallySetViewPivotOnSelection')


    def setViewStateOperationDefaults_DefaultTumblePivot(self,pivotNum):
        '''

        :param pivotNum: 0 - Keep Pivot on Tumble,1 - Set Pivot on Tumble
        :return:
        '''
        if pivotNum == 0:
            hou.setPreference('viewport.setpivottumbledefault.val','0')
            # print('1')
        elif pivotNum==1:
            hou.setPreference('viewport.setpivottumbledefault.val','1')
            # print('0')

    def getViewStateOperationDefaults_DefaultTumblePivot(self):
        return hou.getPreference('viewport.setpivottumbledefault.val')
        # print('getViewStateOperationDefaults_DefaultTumblePivot')


    def setViewStateOperationDefaults_DefaultDollyDirection(self,directionNum):
        '''

        :param directionNum: 0 - Dolly along View Direction,
        1 - Dolly along Projected Direction
        :return:
        '''
        if directionNum == 0:
            hou.setPreference('viewport.directeddollydefault.val', '0')
            # print('1')
        elif directionNum==1:
            hou.setPreference('viewport.directeddollydefault.val', '1')
            # print('0')

    def getViewStateOperationDefaults_DefaultDollyDirection(self):
        return hou.getPreference('viewport.directeddollydefault.val')
        # print('getViewStateOperationDefaults_DefaultDollyDirection')


    def setViewStateOperationDefaults_DefaultZoomCenter(self,centerNum):
        '''

        :param centerNum: 0 - Zoom about View Center,
        1 - Zoom about Mouse Position
        :return:
        '''
        if centerNum == 0:
            hou.setPreference('viewport.offsetzoomdefault.val', '0')
            # print('0')
        elif centerNum == 1:
            hou.setPreference('viewport.offsetzoomdefault.val', '1')
            # print('1')

    def setDelayInactiveViewportRedraws(self,bool):
        if bool == True:
            hou.setPreference('viewport.delayinactive.val','1')
            # print('1')
        else:
            hou.setPreference('viewport.delayinactive.val','0')
            # print('0')

    def getDelayInactiveViewportRedraws(self):
        return hou.getPreference('viewport.delayinactive.val')
        # print('getDelayInactiveViewportRedraws')

    def setDelayInactiveViewportRedraws(self,bool):

        if bool == True:
            hou.setPreference('viewport.allowadaptivesubd.val', '1')
            # print('1')
        else:
            hou.setPreference('viewport.allowadaptivesubd.val', '0')
            # print('0')

    def getDelayInactiveViewportRedraws(self):
        return hou.getPreference('viewport.allowadaptivesubd.val')
        # print('getDelayInactiveViewportRedraws')


    def setHighlightComponentUnderMouseWhenSelecting(self,bool):

        if bool == True:
            hou.setPreference('viewport.locatecomponents.val','1')
            # print('1')
        else:
            hou.setPreference('viewport.locatecomponents.val','0')
            # print('0')

    def getHighlightComponentUnderMouseWhenSelecting(self):
        return hou.getPreference('viewport.locatecomponents.val', '0')
        # print('getHighlightComponentUnderMouseWhenSelecting')